package org.github.rayson517.easyplatform.common.web.jwt;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.github.rayson517.easyplatform.common.web.util.ThreadLocalUtil;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import lombok.extern.log4j.Log4j2;

@Log4j2
public class JwtTokenInterceptor implements HandlerInterceptor {

	private Long startTime;
    private Long endTime;
    
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        startTime = new Date().getTime();
        
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
            ModelAndView modelAndView) throws Exception {
        // TODO Auto-generated method stub
       
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
    	
    	// 清除TheadLocal当中的数据
        ThreadLocalUtil.reset();
        endTime = new Date().getTime();
        log.info("总耗时 {} ms", endTime - startTime);
    }
}
